<?php

class Languages_Translate {

    public $fr_es, $de, $en;
    public $lang;
    private static $_instance;

    public static function getInstance() {
        if (!self::$_instance) {
            self::$_instance = new Languages_Translate();
        }
        return self::$_instance;
    }

    public function __construct() {
        $this->en = new Zend_Translate(
                        array(
                            'adapter' => 'csv',
                            'content' => APPLICATION_PATH . '/languages/en.csv',
                            'locale' => 'en',
                            'delimiter' => ','
                        )
        );
        $this->fr_es = new Zend_Translate(
                        array(
                            'adapter' => 'tmx',
                            'content' => APPLICATION_PATH . '/languages/local.tmx',
                            'locale' => 'fr'
                        )
        );
    }

    public function translate($string) {
        $this->lang = $_SESSION['lang'];
        switch ($this->lang) {
            case 'es':
                $this->fr_es->setLocale('es');
                return $this->fr_es->_($string);
                break;
            case 'de':
                //return $this->fr_es->_($string);
                break;
            case 'en':
                return $this->en->_($string);
                break;
            case 'fr':
            default:
                $this->fr_es->setLocale('fr');
                return $this->fr_es->_($string);
        }
        return $string;
    }

    public function setLang($lang) {
        if(!$lang)
            $this->lang = $lang;
        else{
            $this->lang = $_SESSION['lang'];
        }
    }

}
